/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package servlet.edt;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;

/**
 *
 * @author redaniel
 */
public class SuppCren extends HttpServlet {
   
    /** 
     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        PrintWriter out = response.getWriter();
        
        try {
            
            Connection con;

            String j = (request.getParameter("jour") == null) ? "" : request.getParameter("jour");
            String sal = (request.getParameter("salle") == null) ? "" : request.getParameter("salle");
            Short horaired = (request.getParameter("horairedebut") == null) ? 0 : Short.parseShort(request.getParameter("horairedebut"));
            Short horairef = (request.getParameter("horairefin") == null) ? 0 : Short.parseShort(request.getParameter("horairefin"));
            
            //Suppression
            //demander grouper bd fonction pour tester existance creaneau + suppression

            if(1==1){

                Class.forName("com.mysql.jdbc.Driver");
                con =DriverManager.getConnection ("jdbc:mysql://localhost:8084/miage03.dmiage.u-paris10.fr", "m12009", "m12009pw");

                Statement stmt = con.createStatement();
                ResultSet rs = stmt.executeQuery("SELECT * FROM créneau "); //WHERE date = "+j+" and N°salle = "+sal+" and horairedebut = "+horaired+" and horairefin = "+horairef+";");


                while(rs.next())
                {
                out.println("<LI>" + rs.getString("horaire"));
                }

                rs.close();
                stmt.close();

                out.println("Suppression effectuée du créneau :");
                out.println("\nDate : " + j);
                out.println("\nDébut : " + horaired);
                out.println("\nFin : " + horairef);
                out.println("\nJour : " + sal);
            }else{
                out.println("Suppression impossible.");
            }
        }
        catch(Exception e){
            e.printStackTrace(out);
        }
        finally {
            out.close();
        }
    } 

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** 
     * Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    } 

    /** 
     * Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     * @throws ServletException if a servlet-specific error occurs
     * @throws IOException if an I/O error occurs
     */
    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        processRequest(request, response);
    }

    /** 
     * Returns a short description of the servlet.
     * @return a String containing servlet description
     */
    @Override
    public String getServletInfo() {
        return "Short description";
    }// </editor-fold>

}
